const Deque = require('./deque.js');

function palindromeChecker(aString) {
  if (aString === undefined || aString === null || aString === '') {
    return false;
  }
  const deque = new Deque();
  const lowerString = aString.toLocaleLowerCase().split(' ').join('');
  let startStr;
  let endStr;
  let isEqual = true;

  for (const str of lowerString) {
    startStr = deque.removeFront();
    endStr = deque.removeBack();
    if (startStr !== endStr) {
      isEqual = false;
    }
  }

  return isEqual;
}

console.log('madam', palindromeChecker('madam'));
console.log('palic', palindromeChecker('palic'));
console.log('a', palindromeChecker('a'));
console.log('aa', palindromeChecker('aa'));
console.log('kayak', palindromeChecker('kayak'));
console.log('level', palindromeChecker('level'));
console.log('Was it a car or a cat I saw', palindromeChecker('Was it a car or a cat I saw'));
console.log('Step on no pets', palindromeChecker('Step on no pets'));

// function bookPalindromeChecker(aString) {
//   if (
//     aString === undefined ||
//     aString === null ||
//     (aString !== null && aString.length === 0)
//   ) {
//     return false;
//   }

//   const deque = new Deque();
//   const lowerString = aString
//     .toLocaleLowerCase()
//     .split(' ')
//     .join('');
//   let isEqual = true;
//   let firstChar;
//   let lastChar;

//   for (let i = 0; i < lowerString.length; i++) {
//     deque.addBack(lowerString.charAt(i));
//   }

//   while (deque.size() > 1 && isEqual) {
//     firstChar = deque.removeFront();
//     lastChar = deque.removeBack();
//     if (firstChar !== lastChar) {
//       isEqual = false;
//     }
//   }

//   return isEqual;
// }

// console.log('bookPalindromeChecker madam : ', bookPalindromeChecker('madam'));
// console.log('bookPalindromeChecker palic : ', bookPalindromeChecker('palic'));
